package com.disgruntledbots;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;



public class DamageablePhysicsEntity extends PhysicsEntityConnector {

	int mHealth;
	int mPoints;
	float durability;
	
	public DamageablePhysicsEntity(float X, float Y, ITextureRegion texture, VertexBufferObjectManager vbom, PhysicsWorld pWorld, 
			float mass, float elasticity, float friction)
	{
		super(X, Y, texture, vbom, pWorld, mass, elasticity, friction);
		mHealth = 1;
		mPoints = 1;
	}
	
	public void setAttributes(String name, int health, int pointValue, float durability)
	{
		super.setAttributes(name);
		this.mHealth = health;
		this.mPoints = pointValue;
		
	}
	
	public void recieveDamage(Body collidingBody)
	{
		float damage;
		float impulse;
		Vector2 velocitySum;
		
		velocitySum = this.mBody.getLinearVelocity().sub(collidingBody.getLinearVelocity());
		impulse = velocitySum.len() * collidingBody.getMass();
		
		if(impulse < 0)
		{
			impulse *= -1f;
		}
		
		damage = impulse/durability;
		this.mHealth -= (int)damage;
	}
}
